package cn.sll.system.controller;

import cn.sll.base.util.AjaxResult;
import cn.sll.base.util.PageList;
import cn.sll.system.domain.SystemDictionAryDetail;
import cn.sll.system.query.SystemDictionAryDetailQuery;
import cn.sll.system.service.ISystemDictionAryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdad")
public class SystemDictionAryDetailController {

    @Autowired
    private ISystemDictionAryDetailService systemDictionAryDetailService;

    @GetMapping
    public List<SystemDictionAryDetail> list(){
        return systemDictionAryDetailService.findAll();
    }

    @GetMapping("/{id}")
    public SystemDictionAryDetail findById(@PathVariable("id") Long id){
        return systemDictionAryDetailService.findById(id);
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionAryDetail systemDictionAryDetail){

            if (systemDictionAryDetail.getId()!=null){
                systemDictionAryDetailService.update(systemDictionAryDetail);
            }else {
                systemDictionAryDetailService.add(systemDictionAryDetail);
            }
        return  AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id) {
        systemDictionAryDetailService.delete(id);
        return  AjaxResult.me().success();
    }

    @PostMapping
    public PageList<SystemDictionAryDetail> queryByPage(@RequestBody SystemDictionAryDetailQuery query){
        return systemDictionAryDetailService.queryByPage(query);
    }

    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        systemDictionAryDetailService.batchDelete(ids);
        return AjaxResult.me().success();
    }

    @GetMapping("/findByTypesId/{typesId}")
    public List<SystemDictionAryDetail> findByTypesId(@PathVariable("typesId") Long typesId){
        return systemDictionAryDetailService.findByTypesId(typesId);
    }

}
